﻿ 
@using System.Data;
@{
    var sql = @" and ParentTypeID in( 
                SELECT ID
                  FROM  Mc_ProductType
                  where  
                    ParentTypeID IN (
                      SELECT id FROM dbo.Mc_ProductType WHERE ParentTypeID = '00000000-0000-0000-0000-000000000000'
                 )
                )";
    
     DataTable dt = V5.GZProduct.Query_By_List("*", sql, " ClassCode asc", 15);
    
 } 

<div class="upbox">
  <table width="100%" border="0" cellspacing="1" cellpadding="0" class="main">
    <tr>
      <td valign="top">
      <div class="left_box">
          <div class="leftmenu">
            <ul class="menu"> 
                <li>
                <a class="m_open">商品分类</a>
                @if(dt!=null&&dt.Rows.Count>0)
                {
                            
                <ul>
                    @foreach(DataRow dr in dt.Rows)
                    {
                        <li><a href="javascript:;" data-id="@dr["ID"]" class="tree_child">@dr["TypeName"]</a></li>
                    } 
                </ul>
                }
                </li> 
            </ul>
          </div> 
        </div>
        </td>
      <td valign="top">
          <div  id="table_list" class="middle_box"></div>
        </td>
      <td valign="top"><div class="right_box">
          <h3>已选商品</h3>
          <ul class="plist" id="plist">
            <li><span class="row1" style="text-align:center; text-indent:0"><strong>名称</strong></span><span class="row2" style="text-align:center"><strong>数量</strong></span><span class="row3" style="text-align:center"><strong>操作</strong></span></li>
            </ul>
        </div></td>
    </tr>
    <tr>
      <td colspan="3" align="center" class="xgbtn" >
          <input id="btn_Save" type="button" value="提交" />
          <input id="btn_Cancel" type="button" value="取消" />
      </td>
    </tr>
  </table>
</div>



<script>


    var setSelBtn = function () {
        $(".item_flow_select").off();
        $(".item_flow_select").bind("click", function () {
            var id = $(this).attr("data-id");
            var num = parseInt($("#txt_input_" + id).val());
            var title = $(this).attr("data-name");
            var total = parseInt($(this).attr("data-total"));
             
            if (isNaN(num) || num < 1 || num > total) {
                alert("你输入的数量有误！位置：" + title);
                return false;
            }

            var html = "<li  data-id='" + id + "' data-num='" + num + "' data-total='" + total + "' class='t'><span class='row1'>" + title + "</span>";
            html += "<span class='row2'>" + num + "</span>";
            html += "<span class='row3'><a href='javascript:;' class='sel_item_del'>删除</a></span></li>";

            $("#plist").append(html);

            $("#t_list_" + id).remove();

        });

    }


    $(function () {
        $("#btn_Save").bind("click", function () {

            if ($("#plist .t").length > 0) {
                var Str = "";

                $("#plist .t").each(function () {

                    var id = $(this).attr("data-id");
                    var num = parseInt($(this).attr("data-num"));
                    var total = parseInt($(this).attr("data-total"));

                    if (isNaN(num) || num < 1 || num > total) {
                        alert("你输入的数量有误！位置：" + title);
                        return false;
                    }

                    Str += id + ":" + num + ",";
                });
                if (Str.indexOf(',') > 0)
                    Str = Str.substring(0, Str.length - 1);

                SelectResult(Str);
            }
            else {
                alert("请先选择商品！");
            }

        });



        $("#btn_Cancel").bind("click", function () {
            $("#ProdDialog").dialog('close');
        });


        $(".tree_child").bind("click", function () {
            showLoading();
            $.ajax({
                type: "Post",
                url: "/index.aspx?t=user/getProd",
                data: "k=" + $(this).attr("data-id"),
                success: function (result) {
                    $("#table_list").html(result).show();
                    setSelBtn();
                    setColor();
                },
                complete: function () {
                    hideLoading();
                }
            });

        });

        setSelBtn();
         
        $(".sel_item_del").live("click", function () {
            $(this).parent().parent().remove();
        });

        $(".m_close").live("click", function () {
            $(this).attr("Class", "m_open");
            $(this).siblings("ul").show();
        });

        $(".m_open").live("click", function () {
            $(this).attr("Class", "m_close");
            $(this).siblings("ul").hide();
        });

    });


    var setColor = function () {
        $("#plist li.t").each(function () { 
            $("#t_list_" + $(this).attr("data-id")).addClass("ItemSelected");
        });
    }


   

</script>


